package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.api.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.api.domain.StrategyContent;
import cn.wolfcode.wolf2w.business.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.business.service.IStrategyContentService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.business.query.StrategyQuery;
import cn.wolfcode.wolf2w.business.service.IStrategyService;
import cn.wolfcode.wolf2w.api.domain.Strategy;
import cn.wolfcode.wolf2w.common.security.annotation.RequiresLogin;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 攻略 Controller
 * 
 * @author 浪兎兎
 * @date 2025-05-30
 */
@RestController
@RequestMapping("strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyContentService strategyContentService;
    /**
     * 攻略详情
     */
    @GetMapping("/detail/{id}")
    public R<Strategy> detail(@PathVariable Long id) {
        Strategy strategy = strategyService.getById(id);
        StrategyContent content = strategyContentService.getById(id);
        strategy.setContent(content);
        return R.ok(strategy);
    }
    /**
     * 攻略 列表
     */
    @GetMapping("/query")
    public R<IPage<Strategy>> query(StrategyQuery qo) {
        IPage<Strategy> page = strategyService.queryPage(qo);
        return R.ok(page);
    }

    /**
     * 游记概述
     */
    @GetMapping("/catalogList")
    public R<List<StrategyCatalog>> catalogList(Long destId) {
        return R.ok(strategyCatalogService.catalogList(destId));
    }

    /**
     * 阅读量前三
     */
    @GetMapping("/viewnnumTop3")
    public R<List<Strategy>> viewnumTop3(Long destId) {
        return R.ok(strategyService.getViewNumberTop3(destId));
    }

    /**
     * 获取阅读量
     */
    @PostMapping("/viewnumIncr")
    public R<Map<String, Object>> viewnumIncr(Long sid) {
        return R.ok(strategyService.getViewStatusNumber(sid));
    }

    /**
     * 评论数 + 1
     */
    @PostMapping("/replynumIncr")
    public R<Map<String, Object>> replynumIncr(Long sid) {
        return R.ok(strategyService.getReplyNumber(sid));
    }

    /**
     * 收藏
     */
    @PostMapping("/favor")
    @RequiresLogin
    public R<Map<String, Object>> favor(Long sid) {
        return R.ok(strategyService.favor(sid));
    }

    /**
     * 查询收藏状态
     */
    @GetMapping("/isUserFavor")
    public R<Boolean> isUserFavor(Long sid, Long uid) {
        return R.ok(strategyService.isFavor(sid, uid));
    }

    /**
     * 点赞
     */
    @PostMapping("/thumbsup")
    @RequiresLogin
    public R<Map<String, Object>> thumbsup(Long sid) {
        return R.ok(strategyService.thumbsup(sid));
    }


    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Strategy>> feignList() {
        return R.ok(strategyService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Strategy> feignGet(@PathVariable Long id) {
        return R.ok(strategyService.getById(id));
    }
    @PostMapping("/feign/statusPersistence")
    public R<?> statusPersistence() {
        strategyService.statusPersistence();
        return R.ok();
    }
    @PostMapping("/feign/statisHashPersistence")
    R<?> statisHashPersistence(){
        strategyService.statisHashPersistence();
        return R.ok();
    }

    @PostMapping("/feign/strategyRankStatis")
    R<?> strategyRankStatis(){
        strategyService.strategyRankStatis();
        return R.ok();
    }

    @PostMapping("/feign/reSendStrategyMessage")
    R<?> reSendStrategyMessage(){
        strategyService.reSendStrategyMessage();
        return R.ok();
    }


}
